﻿using System.Windows;
using System.Windows.Navigation;
using DepSoft.Mobile.WP8.FollwIt.Messages;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Phone.Controls;
using Microsoft.Practices.ServiceLocation;
using SlideView.Library;

namespace DepSoft.Mobile.WP8.FollwIt.View
{
    public partial class MoviesPage : PhoneApplicationPage
    {
        private SlideApplicationFrame _rootFrame = (SlideApplicationFrame)App.RootFrame;
        private string _navigationKey;

        public MoviesPage()
        {
            InitializeComponent();            
            _rootFrame.IsSlideEnabled = true;

            this.Loaded += OnViewLoaded;
        }

        private void OnViewLoaded(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(_navigationKey))
                ServiceLocator.Current.GetInstance<IMessenger>().Send(new FollwItUserMessage(_navigationKey), Tokens.ForMovies);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            _rootFrame.Title = "movies";

            _navigationKey = "";
            NavigationContext.QueryString.TryGetValue("key", out _navigationKey);
        }
    }
}